package git.soulbgm.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import git.soulbgm.common.base.BaseController;
import git.soulbgm.common.pojo.QueryDto;
import git.soulbgm.common.pojo.Response;
import git.soulbgm.pojo.NodeNtpdateStatus;
import git.soulbgm.service.NodeNtpdateStatusService;
import git.soulbgm.utils.EasyPoiUtil;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 时间同步控制器
 *
 * @author SoulBGM
 * @date 2022/03/11 10:28
 */
@RestController
@RequestMapping("system/nodeNtpdate")
public class NodeNtpdateController extends BaseController {

    private final NodeNtpdateStatusService nodeNtpdateStatusService;

    public NodeNtpdateController(NodeNtpdateStatusService nodeNtpdateStatusService) {
        this.nodeNtpdateStatusService = nodeNtpdateStatusService;
    }

    @PostMapping("list")
    public Response list(@RequestBody QueryDto<NodeNtpdateStatus> dto, Page<NodeNtpdateStatus> queryPage) {
        Page<NodeNtpdateStatus> resultPage = nodeNtpdateStatusService.page(queryPage, new QueryWrapper<>(dto.getData()));
        return success(resultPage);
    }

    @GetMapping("export")
    public void export(NodeNtpdateStatus info, HttpServletResponse response) {
        List<NodeNtpdateStatus> list = nodeNtpdateStatusService.list(new QueryWrapper<>(info));
        try {
            EasyPoiUtil.exportExcel(response, "时间同步数据", list, NodeNtpdateStatus.class);
        } catch (IOException e) {
            throw new RuntimeException("导出失败");
        }
    }

}
